package com.yc.shadowdemo.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.yc.commontlib.base.YcBaseViewModel
import com.yc.commontlib.base.YcRepository
import com.yc.commontlib.net.YcNetUtil
import com.yc.commontlib.net.YcResult
import com.yc.commontlib.net.YcRetrofitUtil
import com.yc.shadowdemo.data.json.VersionJson
import com.yc.shadowdemo.net.ApiService
import com.yc.shadowdemo.repository.VersionRepository
import kotlinx.coroutines.flow.collectLatest

/**
 * Creator: yc
 * Date: 2021/6/15 18:03
 * UseDes:
 */
class WelcomeVM : YcBaseViewModel() {
    private val mApiService: ApiService by lazy {
        YcRetrofitUtil.Instance.getApiService(ApiService::class.java)
    }
    private val mVersionRepository: VersionRepository by lazy { VersionRepository(mApiService) }


    private val _mVersion = MutableLiveData<YcResult<VersionJson>>()
    val mVersion: LiveData<YcResult<VersionJson>> = _mVersion
    fun checkVersion() = launch {
        mVersionRepository.getVersion().collectLatest {
            _mVersion.postValue(it)
        }
    }
}